package com.example.zxapigateway.config;

import com.example.zxapigateway.filters.InterfaceFilter;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author 张旭
 * @version 1.0
 */
@Configuration
public class GatewayConfig {

    @Resource
    private InterfaceFilter interfaceFilter;

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("zxapi-interface", r -> r.path("/api/interface")
                        .filters(f -> f.filter(interfaceFilter))
                        .uri("lb://zxapi-interface"))
                .build();
    }

}
